package com.nondo.dean.product.controller.api.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.tool.AliyunOssTool;
import com.nondo.dean.common.web.View;
import com.nondo.dean.product.domain.ProductWithBLOBs;
import com.nondo.dean.product.model.AppProductBean;
import com.nondo.dean.product.model.ProductBean;
import com.nondo.dean.product.service.ProductService;

/**
 * @author ken.
 * @version 1.0
 * @email 695093513@qq.com
 * @date 2018/4/12
 */
@RestController("apiAppProduct")
@RequestMapping("/{v}/app/product")
public class ProductController {

    @Autowired
    ProductService productService;

    @Autowired
    AliyunOssTool aliyunOssTool;

    /**
     * 获取产品基本信息
     *
     * @param request
     * @param response
     * @param productId
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/info/{id}")
    public View<AppProductBean> productInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer productId) {
        View<AppProductBean> view = new View<AppProductBean>(20000, "获取数据成功");

        AppProductBean appProductBean = new AppProductBean();

        ProductBean productBean = this.productService.findById(productId);
        
        if (productBean == null) {
            view.setMessage("产品不存在");
            return view;
        }
        appProductBean = this.productService.getAppProductInfo(productBean);
        view.setData(appProductBean);

        return view;
    }

    /**
     * 获取产品详情描述
     *
     * @param request
     * @param response
     * @param productId
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/info/detail/{id}")
    public View<String> productDetail(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") int productId) {
        View<String>  view = new View<String> (20000, "获取数据成功");

        ProductWithBLOBs productWithBLOBs = this.productService.selectById(productId);
        view.setData(productWithBLOBs.getDetailInfo());

        return view;
    }
}